clear;
q = 10^(40/10);
T = 1e-3;
fi = 10e6;
fj = 1.1*10e6;
f0 = 50e6;
Td = 1/f0;
Tpn = (1e-3)/5110;
A = sqrt(4*q*Td);
PNsize = fix(T/Tpn);
PN = sign(randn(1, PNsize));
Nd = fix(T/Td);
PSP = PN(1 + mod(fix((0:Nd-1)*Td/Tpn), PNsize));
%figure
%plot(PSP)

s = PSP.*cos(2*pi*fi*Td*(0:Nd-1));
for n = 1:1000
y = A*s + randn(1,Nd);
I(n) = y*s';
end
%figure
%plot(I)
Q = 20*log10(mean(I)/std(I)) - 3;

stds = 1;
JS = 10^(60/10);
Aj = A*sqrt(JS);
for n = 1:1000
y = Aj*cos(2*pi*fj*Td*(0:Nd-1)) + A*s + randn(1,Nd);
I(n) = y*s';
end
%plot(I)

S = abs(fft(y));
S = S/max(S);

h = -60;
for k = 1:Nd
    if abs(S(k)) > h
        S(k) = h;
    else
        S(k) = S(k);
    end
end
plot(20*log10(S))
yp = ifft(S);

yi = A*G*cos(2*pi*fi*ti) + ni;